/*
Copyright (C) Ariff Ehsan, Abdul Hadi Fikri

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

/*  Author : Ariff Ehsan
 *  Date   : June 22, 2009
 */


#include <system.h>
#include <leds4/leds4.h>


void LEDS4_init(void) {
	/* initialize port as output */
	LEDS4_DDR |= (1<<LEDS4_LED0)|(1<<LEDS4_LED1)|(1<<LEDS4_LED2)|(1<<LEDS4_LED3);
	
	/* set initial pins value */
	//LEDS4_PORT &= !((1<<LEDS4_LED0)|(1<<LEDS4_LED1)|(1<<LEDS4_LED2)|(1<<LEDS4_LED3));
}


void LEDS4_on(uint8_t pin) {
	SET_BIT(LEDS4_PORT, pin);
}


void LEDS4_off(uint8_t pin) {
	CLR_BIT(LEDS4_PORT, pin);
}


void LEDS4_set(uint8_t value) {	
#ifdef LEDS4_MSB
	value <<= 4;
	
	LEDS4_PORT &= 0x0f;
	LEDS4_PORT |= value;
	
#else
	value &= 0x0f;
	
	LEDS4_PORT &= 0xf0;
	LEDS4_PORT |= value;
	
#endif
	
}


void LEDS4_toggle(uint8_t pin) {
	FLIP_BIT(LEDS4_PORT, pin);
}

